package com.leetcode.algorithm.y22.m06;

/**
 * 367. 有效的完全平方数
 * 
 * https://leetcode.cn/problems/valid-perfect-square/
 * 
 * @author jie.deng
 *
 */
public class Question0367Solution01 {

	public boolean isPerfectSquare(int num) {
		int left = 1;
		int right = num;
		while (left <= right) {
			int mid = left + ((right - left) >> 1);
			long x = (long) mid * (long) mid;
			if (x == num) {
				return true;
			} else if (x > num) {
				right = mid - 1;
			} else {
				left = mid + 1;
			}
		}
		return false;
	}

}
